//                        ElgProg
//
//    A cheap DIY Arduino based Universal Programmer
//
//    Copyright (C) Elgen };-P aka Morten Overgaard 2015
//
//    This file is part of ElgProg.
//
//    ElgProg is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    ElgProg is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with ElgProg. If not, see <http://www.gnu.org/licenses/>.

#ifndef EpromLib_h
#define EpromLib_h

#include "Arduino.h"
#include "LiquidCrystal.h"

#define debugPrint(message, miliseconds) \
do { \
  lcd->clear(); \
  lcd->print(message); \
  delay(miliseconds); \
} while(false)

class Eprom
{
  public:
    Eprom(LiquidCrystal* lcd, unsigned long dataBufferSize, byte* currentBuffer, byte* nextBuffer);
    ~Eprom();
    void readEprom();
    void readConfig(); 
    void verifyConf();
  private:
    LiquidCrystal* lcd;
    unsigned long dataBufferSize;
    byte* currentBuffer;
    byte* nextBuffer;
    unsigned long addresses;
    int addressPins[43];
    int dataPins[33];
    int cePins[6];
    int oePins[6];
    void verifyConfArray(int* confArray, int* confArrayV, String txt);
    void switchBuffers();
    unsigned long readToBuffer(unsigned long firstAddress, unsigned long allAddresses, unsigned long bufferSize, byte* theBuffer);
    void setPinMode(int mode, int* pins);
    void setPins(int value, int* pins);
    byte readData8Bit(int* pins);
    void writeAddress(unsigned long address, int* pins);
};

#endif //EpromLib_h
